package com.menggudf.service.impl;

import com.menggudf.entity.CaseHistoryImg;
import com.menggudf.mapper.CaseHistoryImgDao;
import com.menggudf.service.CaseHistoryImgService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (CaseHistoryImg)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:26
 */
@Service("caseHistoryImgService")
public class CaseHistoryImgServiceImpl implements CaseHistoryImgService {
    @Resource
    private CaseHistoryImgDao caseHistoryImgDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CaseHistoryImg queryById(Integer id) {
        return this.caseHistoryImgDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param caseHistoryImg 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CaseHistoryImg> queryByPage(CaseHistoryImg caseHistoryImg, PageRequest pageRequest) {
        long total = this.caseHistoryImgDao.count(caseHistoryImg);
        return new PageImpl<>(this.caseHistoryImgDao.queryAllByLimit(caseHistoryImg, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param caseHistoryImg 实例对象
     * @return 实例对象
     */
    @Override
    public CaseHistoryImg insert(CaseHistoryImg caseHistoryImg) {
        this.caseHistoryImgDao.insert(caseHistoryImg);
        return caseHistoryImg;
    }

    /**
     * 修改数据
     *
     * @param caseHistoryImg 实例对象
     * @return 实例对象
     */
    @Override
    public CaseHistoryImg update(CaseHistoryImg caseHistoryImg) {
        this.caseHistoryImgDao.update(caseHistoryImg);
        return this.queryById(caseHistoryImg.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.caseHistoryImgDao.deleteById(id) > 0;
    }
}
